export default class RoadCondHandler {
    constructor() {
        this.layerIds = [
            'road-cond-1',
            'road-cond-2',
            'road-cond-3',
            'road-cond-4',
        ];
        this.legendObj = {
            name: '实时路况',
            arrName: ['严重拥堵', '拥堵', '缓行', '畅通'],
            arrColor: ['#AD1717', '#E53434', '#FF9901', '#66CC01']
        };
        this._interval = null;
    }

    init(map) {
        this.updateSource(map);
        let that = this;
        /*
        this._interval = setInterval(() => {
            that.updateSource(map);
        }, 60000);
        */
    }

    updateSource(map) {
        if (map.getSource('Traffic')) {
            map.removeSource('Traffic');
        }
        map.addSource('Traffic', {
            "type": "vector",
            "tiles": ["minemapdatad://Trafficrtic/{z}/{x}/{y}/" + new Date().getTime()]
        });
    }

    hideRoadCondLayers(map, backgroundId) {
        this.layerIds.map(id => {
            //map.moveLayer(id, backgroundId);
            map.setLayoutProperty(id, 'visibility', 'none');
        });
    }

    showRoadCondLayers(map, topId) {
        this.layerIds.map(id => {
            //map.moveLayer(id, topId);
            map.setLayoutProperty(id, 'visibility', 'visible');
        });
    }

    setValueNum(map, valueNum) {
        if (valueNum === 24) valueNum = 0;
        const source = map.getSource("HistXian");
        if (source) {
            source._eventedParent._rticCache.updateTimeStamp(valueNum);
            source._eventedParent._rticCache.reloadSeparateTile();
        }
    }

    getLegendObj() {
        return this.legendObj;
    }
};